Imports pixolut.BizBlox
Imports System.Text

Public Class VBDOCollectionRenderEngine
    Inherits VBAbstractRenderEngine

    Public Sub New(ByVal u As UpdateProgress, ByVal s As UpdateStatus)
        MyBase.New(u, s, GetType(SQL))
    End Sub

    Protected Overrides Function FormatFilename(ByVal tableName As String) As String
        Return tableName & "Collection"
    End Function

    Protected Overrides Function RenderPrefix(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append("Imports pixolut.BizBlox").Append(vbCrLf).Append(vbCrLf)
        sb = sb.Append("Public Class ").Append(t.TableName).Append("Collection").Append(vbCrLf)
        sb = sb.Append("    Inherits DOCollection").Append(vbCrLf)
        sb = sb.Append(vbCrLf)
        Return sb.ToString()
    End Function

    Protected Overrides Function RenderPostfix(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append(vbCrLf)
        sb = sb.Append(vbCrLf)
        sb = sb.Append("    'Example finder method").Append(vbCrLf)
        sb = sb.Append("    '*********************").Append(vbCrLf)
        sb = sb.Append("    'Public Sub FindBy(ByVal name As String)").Append(vbCrLf)
        sb = sb.Append("    '    Dim mySql As SqlBuilder = MyBase.GetSqlBuilder()").Append(vbCrLf)
        sb = sb.Append("    '    mySql.addWhere(" & t.TableName & ".Columns.Name, name)").Append(vbCrLf)
        sb = sb.Append("    '    MyBase.SetCurrentQuery(mySql)").Append(vbCrLf)
        sb = sb.Append("    'End Sub").Append(vbCrLf)
        sb = sb.Append("End Class").Append(vbCrLf)
        Return sb.ToString()
    End Function

    Protected Overrides Function RenderColumn(ByVal t As Table, ByVal index As Integer) As String
        Return ""
    End Function

    Protected Overrides Function RenderForeignColumn(ByVal t As Table, ByVal index As Integer) As String
        Return ""
    End Function

    Protected Overrides Function RenderElements(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append(vbCrLf)
        sb = sb.Append("    Sub New()").Append(vbCrLf)
        sb = sb.Append("        MyBase.New(New DOFactory(New ").Append(t.TableName).Append("))").Append(vbCrLf)
        sb = sb.Append("    End Sub").Append(vbCrLf).Append(vbCrLf)
        sb = sb.Append("    'to typecast your item() property").Append(vbCrLf)
        sb = sb.Append("    Default Public Shadows ReadOnly Property Item(ByVal i As Integer) As ").Append(t.TableName).Append(vbCrLf)
        sb = sb.Append("        Get").Append(vbCrLf)
        sb = sb.Append("            Return CType(MyBase.Item(i), ").Append(t.TableName).Append(")").Append(vbCrLf)
        sb = sb.Append("        End Get").Append(vbCrLf)
        sb = sb.Append("    End Property").Append(vbCrLf)
        sb = sb.Append(vbCrLf)

        Return sb.ToString()
    End Function
End Class
